feat(web): add run_server orchestration entry point#110
Conversation
… WebSocket server
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #110 +/- ##
======================================
Coverage ? 99.08%
======================================
Files ? 8
Lines ? 327
Branches ? 0
======================================
Hits ? 324
Misses ? 3
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Asanto32
left a comment
There was a problem hiding this comment.
Some small things to clean up. Can you test _run_server_async directly and then do the outer loop to test run_server?
| Args: | ||
| presenter: The MainAppPresenter providing stream data. | ||
| host: The hostname to bind to. | ||
| port: The port to listen on. |
There was a problem hiding this comment.
Comment on why the default is 8765? seems like a default tcp port?
| logger.info("Note: Web server functionality will be added in future branch") | ||
|
|
||
| schedule_browser_launch() | ||
| web_server.run_server(presenter) |
There was a problem hiding this comment.
Now that this does something should we add a smoke test for main to check we actually open the web page (which has nothing in it right?)
| mock_serve.__aenter__ = AsyncMock() | ||
| mock_serve.__aexit__ = AsyncMock(return_value=False) | ||
|
|
||
| async def _run() -> None: |
There was a problem hiding this comment.
This is essentially replacing your _run_server_async right?
| _, serve_kwargs = mock_serve_fn.call_args | ||
| assert serve_kwargs["process_request"] is server.process_request | ||
|
|
||
| asyncio.run(_run()) |
There was a problem hiding this comment.
Why call this directly instead of your function that calls asyncio.run?
Resolves #105
Adds
run_serverso the app actually starts a WebSocket server and broadcaster when you runmobi-view.run_server(presenter, host, port)serves as the single sync entry point that wires everything together. It callsasyncio.run(_run_server_async())._run_server_asynccreates aBroadcaster, starts its background thread, opens the websockets server with the existingws_handlerandprocess_requesthooks already in place, then blocks until the process receivesSIGINTorSIGTERM. On shutdown, it stops the broadcaster and closes the server cleanly through the normalfinallypath._register_shutdown_signalsusesloop.add_signal_handlerto set anasyncio.Eventwhen either SIGINT or SIGTERM is received. The server awaits that event inside theasync with server.serve()context, so cleanup flows throughfinallypath.main.pynow callsrun_serverinstead of printing a placeholder message.schedule_browser_launchfires before the blockingrun_servercall so the browser opens athttp://localhost:8765once the server is up.